package org.sys.transporttrainsys.service;

import org.sys.transporttrainsys.entity.DocumentVideoType;
import org.sys.transporttrainsys.repository.DocumentVideoTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DocumentVideoTypeService {

    @Autowired
    private DocumentVideoTypeRepository documentVideoTypeRepository;

    public List<DocumentVideoType> getAllDocumentVideoTypes() {
        return documentVideoTypeRepository.findAll();
    }

    public DocumentVideoType getDocumentVideoTypeById(Long id) {
        return documentVideoTypeRepository.findById(id).orElse(null);
    }

    public DocumentVideoType createDocumentVideoType(DocumentVideoType documentVideoType) {
        return documentVideoTypeRepository.save(documentVideoType);
    }

    public DocumentVideoType updateDocumentVideoType(Long id, DocumentVideoType documentVideoTypeDetails) {
        DocumentVideoType documentVideoType = documentVideoTypeRepository.findById(id).orElse(null);
        if (documentVideoType != null) {
            documentVideoType.setTypeName(documentVideoTypeDetails.getTypeName());
            return documentVideoTypeRepository.save(documentVideoType);
        }
        return null;
    }

    public void deleteDocumentVideoType(Long id) {
        documentVideoTypeRepository.deleteById(id);
    }

    public List<DocumentVideoType> searchByTypeName(String name) {
        return documentVideoTypeRepository.findByTypeNameContainingIgnoreCase(name);
    }
}